package site.xying.dd;

import net.milkbowl.vault.economy.Economy;

import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

/**
 * @author: Hisen
 * @date: 2019/2/1 13:06
 * @description:
 */
public class DispatcherPlugin extends JavaPlugin {
  public static DispatcherPlugin plugin;
  private Economy economy;
  private final static String VAULT = "Vault";

  @Override
  public void onEnable() {
    plugin = this;
    Config config = new Config();
    this.setEconomy();

    getServer().getPluginManager().registerEvents(new EventListener(this), this);
    getCommand("DeathDrop").setExecutor(new AllCommand(config));
  }


  /**
   * 设置经济插件
   */
  private void setEconomy() {
    if (Bukkit.getPluginManager().getPlugin(VAULT) != null) {
      RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(Economy.class);
      if (economyProvider != null) {
        this.economy = economyProvider.getProvider();
      }
    }
  }

  public Economy getEconomy(){
    return this.economy;
  }
}
